package com.microservice.provider.controller;

import com.microservice.common.R;
import com.microservice.provider.dto.UserDTO;
import com.microservice.provider.entity.UserEntity;
import com.microservice.provider.feign.UserFeignClient;
import com.microservice.provider.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * write something please~
 *
 * @author huangrz
 * @since 2021/9/9
 **/
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController implements UserFeignClient {

    @Autowired
    private UserService userService;
    @Autowired
    private ModelMapper modelMapper;

    @GetMapping("/get/{id}")
    @Override
    public R<UserDTO> get(Long id) {
        UserEntity userEntity = userService.getById(id);
        if (userEntity == null) {
            throw new IllegalArgumentException("error user id");
        }
        return R.ok(modelMapper.map(userEntity, UserDTO.class));
    }

}
